package com.jungle.mvvm.sample.ui.collect;

import android.support.annotation.NonNull;

import com.jungle.mvvm.base.ItemViewModel;
import com.jungle.mvvm.binding.command.BindingAction;
import com.jungle.mvvm.binding.command.BindingCommand;
import com.jungle.mvvm.sample.bean.CollectBean;
import com.jungle.mvvm.sample.util.ArticleUtil;

/**
 * @ClassName CollectItemViewModel
 * @Description CollectItemViewModel
 * @Author Daniel
 * @Version V1.0.0
 */
public class CollectItemViewModel extends ItemViewModel<CollectViewModel> {
    private CollectBean mCollectBean;

    public CollectItemViewModel(@NonNull CollectViewModel viewModel, CollectBean collectBean) {
        super(viewModel);
        this.mCollectBean = collectBean;
    }

    public CollectBean getCollectBean() {
        return mCollectBean;
    }

    //条目的点击事件
    public BindingCommand itemClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            ArticleUtil.toDetail(mCollectBean.getTitle(), mCollectBean.getLink(), viewModel);
        }
    });

    public BindingCommand collectClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            int position = viewModel.observableList.indexOf(CollectItemViewModel.this);
            ArticleUtil.toCollect(mCollectBean, position, viewModel);
        }
    });
}